package demo3;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 石方旭
 * Date: 2022-07-31
 * Time: 11:48
 */
public class TestDemo1 {

    public static Object locker1 = new Object();
    public static Object locker2 = new Object();
    public static void main(String[] args) {
        //对不同对象加锁不会产生锁竞争
        Thread t1 = new Thread(()->{
            synchronized(locker1){
                System.out.println("t1  --> start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t1  --> end");
            }
        });
        t1.start();
        Thread t2 = new Thread(()->{
            synchronized(locker2){
                System.out.println("t2  --> start");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("t2  --> end");
            }
        });
        t2.start();

    }

}
